var app = getApp();
Page({
    data:{
        siteroot : app.siteInfo.siteroot.replace('app/index.php', ''),uniacid: app.siteInfo.uniacid,
        isIPX : app.globalData.isIPX,
        info : {},
        morecard : false,
        tabtype : 0,
        params : {},
		
    },
    onLoad:function(options){
        var self = this;
        if( options.scene ){
            var list = options.scene.split('_');
            options.id = list[0] ? list[0] : 0;
            options.zfid = list[1] ? list[1] : 0;
        }

        var id = options.id ? options.id : ( options.scene ? options.scene : 0 );
        var zfid = options.zfid ? options.zfid : '';
        self.data.options = options;
        
        app.com.getLocation(self,function(loc){
            app.com.auth(function(){

                var postdata = {
                    op : 'tradeinfo',
                    id : id,
                    zfid : zfid,
                    lat : loc.latitude,
                    lng : loc.longitude,
                    isinit : self.data.info.id ? 1 : 0,
                }

                app.com.http('shop_v1','POST',postdata,0,false,'','',function(res){
                    if (res.data && !res.data.errno) {

                        self.setData({
                            inited : true,
                            info : res.data.data.info ? res.data.data.info : {},
                            sharedata : res.data.data.sharedata,
                            params : res.data.data.params,
                        },function(){

                            if( res.data.data.info.content ){
                                
                                var octoparse = require('../resource/wxParse/html2json2.js');
                                var transData = octoparse.parse(res.data.data.info.content);                   
                                self.setData({
                                    nodes : transData,
                                })
                            }

                        }) 

                        wx.setNavigationBarTitle({
                            title: res.data.data.info.name
                        });
                        
                    }else{
                        app.com.alert(res.data.message,function(){
                            app.com.backPage(options.zfid);
                        });
                    }
                });
            });
        })
    },
    onPullDownRefresh: function () {
        if( this.data.isdown ) return false;
        this.onLoad( this.data.options );
        this.data.isdown = false;

        wx.stopPullDownRefresh();
    },
    onShareAppMessage : function(){
        var self = this;
        return {
            title: self.data.sharedata.title,
            path: self.data.sharedata.path,
            imageUrl : self.data.sharedata.img,
        }
    },
    back(){
        app.com.backPage();
    },
    location : function( e ){
        app.com.location( e );
    },
    otherapp : function( e ){
        app.com.otherapp( e );
    },
    navigateto : function( e ){
        app.com.navigateto( e,this.data.tid );
    },
    redirectto : function( e ){
        app.com.redirectto( e,this.data.tid );
    },    
    callphone : function(e){
        app.com.callphone( e );
    },
    showimages : function( e ){
        app.com.showimages( e );
    },
    footNavigate(e){
        var url = e.currentTarget.dataset.url;
        wx.switchTab({
          url: url
        })
    },
    showJoin(e){
        var self = this;
        self.setData({
            Joinanimation : !self.data.Joinanimation,
        })
    },
    
})